package org.nw.jf.ext.ref;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.nw.dao.PaginationVO;
import org.nw.utils.CorpHelper;
import org.nw.vo.sys.PsndocVO;
import org.nw.web.utils.WebUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


/**
 * 人员档案参照
 * 
 * @author xuqc
 * @date 2012-7-2 下午06:03:15
 */
@Controller
@RequestMapping(value = "/ref/common/psndoc")
public class PsndocDefaultRefModel extends AbstractGridRefModel {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4697550166289979740L;

	@Override
	protected String[] getFieldCode() {
		return new String[] { PsndocVO.PSNCODE, PsndocVO.PSNNAME, PsndocVO.ID };
	}

	@Override
	protected String[] getFieldName() {
		return new String[] { "人员编码", "人员名称", "身份证" };
	}

	@Override
	public Map<String, Object> load4Grid(HttpServletRequest request) {
		String condition = getGridQueryCondition(request, PsndocVO.class);
		String whereClause = this.getExtendCond(request);
		StringBuffer cond = new StringBuffer(" 1=1 ");
		if(StringUtils.isNotBlank(condition)) {
			cond.append(" and ");
			cond.append(condition);
		}
		if(StringUtils.isNotBlank(whereClause)) {
			cond.append(" and ");
			cond.append(whereClause);
		}
		String corpCond = CorpHelper.getCurrentCorp();
		if(StringUtils.isNotBlank(corpCond)) {
			cond.append(" and ");
			cond.append(corpCond);
		}
		int offset = getOffset(request);
		int pageSize = getPageSize(request);
		PaginationVO page = baseRefService.queryForPagination(PsndocVO.class, offset, pageSize, cond.toString());
		return this.genAjaxResponse(true, null, page);
	}

	@Override
	public String getPkFieldCode() {
		return PsndocVO.PK_PSNDOC;
	}

	@Override
	public String getCodeFieldCode() {
		return PsndocVO.PSNCODE;
	}

	@Override
	public String getNameFieldCode() {
		return PsndocVO.PSNNAME;
	}

	@Override
	public Map<String, Object> getByCode(String code) {
		return this.genAjaxResponse(
				true,
				null,
				baseRefService.getVOByCode(PsndocVO.class, code, " pk_corp='" + WebUtils.getLoginInfo().getPk_corp()
						+ "'"));
	}

	@Override
	public Map<String, Object> getByPk(String pk) {
		return this.genAjaxResponse(true, null, baseRefService.getVOByPk(PsndocVO.class, pk));
	}

}
